﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Database.Model.Turnovers>>" %>
<%@ Import Namespace="System.Globalization" %>

<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="DevExpress.Data" %>



<% Html.DevExpress().GridView(settings =>
                                   {
                                       settings.Name = "gdTurnovers";
                                       settings.SettingsPager.PageSize = 20;
                                       settings.KeyFieldName = "IdTurnover";
                                       settings.CallbackRouteValues = new { Controller = "Turnovers", Action = "AllDirectTurnoversPartial" };
                                       settings.Settings.ShowFilterBar = GridViewStatusBarMode.Visible;
                                       
                                       
                                       

                                       settings.Settings.ShowFilterRow = true;
                                       settings.Settings.ShowGroupPanel = true;


                                       settings.Columns.Add(column =>
                                                                {
                                                                    column.Caption = Resourses.Year;
                                                                    column.FieldName = "Year";
                                                                });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.Month;
                                           column.FieldName = "Month";
                                       });


                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.Caption = Resourses.TurnoversAmount;
                                       //    column.FieldName = "EuroAmount";
                                       //    column.PropertiesEdit.DisplayFormatString = "euro";
                                       //});

                                      
                                       
                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TurnoversAmount;
                                           column.FieldName = "Amount";
                                           column.Visible = true;
                                           column.PropertiesEdit.DisplayFormatString = "c";
                                           //column.SetDataItemTemplateContent(c=>
                                           //                                      {
                                           //                                          ViewContext.Writer.Write(c.DataItem.ToString("euro"));
                                           //                                      });

                                       });


                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.Article;
                                           column.FieldName = "ArticleText";
                                           column.Visible = true;
                                          


                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.ProductSystems;
                                           column.FieldName = "ProductSystemName";
                                           column.Visible = true;
                                         


                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.ProductMark;
                                           column.FieldName = "ProductMarkName";
                                           column.Visible = true;
                                          


                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.FieldName = "IdTurnoverClassification";
                                           column.Caption = Resourses.TurnoverClassifications;
                                           column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                           var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                           if (comboBoxProperties != null)
                                           {
                                               var col = new TurnoverClassificationsCollection();

                                               comboBoxProperties.DataSource = col.TurnoverClassificationsList;
                                               comboBoxProperties.TextField = "LocalizedName";
                                               comboBoxProperties.ValueField = "IdTurnoverClassification";
                                               comboBoxProperties.ValueType = typeof(int);
                                           }
                                       });
                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.CustomerNumber;
                                           column.FieldName =  "ClientSequentalNumber";//"IdLegalEntity";
                                           
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.CustomerName;
                                           column.FieldName = "CustomerName";//"IdLegalEntity";

                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.LegalEntityName;
                                           column.FieldName = "LegalEntityName";//"IdLegalEntity";

                                       });


                                    

                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.Caption = Resourses.Districts;
                                       //    column.FieldName = "";
                                       //});

                                      

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.customerRegion;
                                           column.FieldName = "IdProfineRegionLegalEntity";

                                           column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                           var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                           if (comboBoxProperties != null)
                                           {
                                               var col = new profineRegionsCollection();

                                               comboBoxProperties.DataSource =
                                                   col.profineRegionsList;
                                               comboBoxProperties.TextField = "LocalizedName";
                                               comboBoxProperties.ValueField = "IdProfineRegion";
                                               comboBoxProperties.ValueType = typeof(int);
                                           }
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.DealerLegalName;
                                           column.FieldName = "DealerLegalName";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.Dealer;
                                           column.FieldName = "DealerName";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.DealerProfineRegion;
                                           column.FieldName = "DealerProfineRegionName";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.customerCity;
                                           column.FieldName = "DealerCity";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.customerManager;
                                           column.FieldName = "ManagerName";
                                       });


                                       settings.TotalSummary.Add(SummaryItemType.Sum, "Amount").DisplayFormat = Resourses.Total+": {0:c}";
                                       

                                       settings.GroupSummary.Add(SummaryItemType.Sum, "Amount").DisplayFormat   = Resourses.Total+": {0:c}";

                                       settings.CustomColumnDisplayText = (sender, e) =>
                                       {

                                           if (e.Column.FieldName == "Amount")
                                           {


                                               e.DisplayText = ((float)e.Value).ToString("c", CultureInfo.CreateSpecificCulture("fr-FR"));



                                           }
                                       };
                                       settings.SummaryDisplayText = (sender, e) =>
                                       {
                                           if (e.Item.FieldName == "Amount")
                                           {
                                               decimal value;
                                               decimal.TryParse(e.Value.ToString(), out value);
                                               e.Text = Resourses.Total + ": " + value.ToString("c", CultureInfo.CreateSpecificCulture("fr-FR"));
                                               // e.Text = value.ToString("euro", null);
                                           }
                                       };
                                       
                                       
                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.FieldName = "IdLegalEntity";
                                       //    column.Caption = Resourses.LegalEntities;
                                       //    column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                       //    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                       //    if (comboBoxProperties != null)
                                       //    {

                                       //        comboBoxProperties.DataSource =
                                       //            DB.GetLegalEntitiesFromTurnovers(Model);

                                       //        comboBoxProperties.TextField = "Name";
                                       //        comboBoxProperties.ValueField = "IdLegalEntity";
                                       //        comboBoxProperties.ValueType = typeof(int);
                                       //    }
                                       //});
                                       
                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.Caption = Resourses.TurnoversPeriod;
                                       //    column.FieldName = "Period";
                                       //});

                                       ////
                                       ////Добавление комбобоксов
                                       ////
                                      

                                       ////
                                       ////Добавление комбобоксов
                                       ////
                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.FieldName = "IdDealerLegalEntity";
                                       //    column.Caption = Resourses.TurnoversDealers;
                                       //    column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                       //    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                       //    if (comboBoxProperties != null)
                                       //    {

                                       //        comboBoxProperties.DataSource =
                                       //            DB.LegalEntities;

                                       //        comboBoxProperties.TextField = "Name";
                                       //        comboBoxProperties.ValueField = "IdLegalEntity";
                                       //        comboBoxProperties.ValueType = typeof(int);
                                       //    }
                                       //});

                                       
                                       settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                       settings.Width = Unit.Percentage(100);
                                       settings.Settings.ShowFooter = true;
                                       settings.PreRender = (sender, e) =>
                                       {
                                           MVCxGridView gridView = sender as MVCxGridView;
                                           if (gridView != null)
                                               gridView.FilterExpression = "Year > 2011";
                                       };
                                       //конец комбобокса
                                   }
        ).Bind(Model).GetHtml();
%>
